<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<script type="text/javascript">
$(document).ready(function(){
	$("#delivery_se1").click(function (){
		if($("#buyer_chg_name")){
			$("#receive_name").val($("#buyer_chg_name").val());
			$("#receive_cell").val($("#buyer_chg_cell").val());
			$("#receive_email").val($("#buyer_chg_email").val());
		}else{
			$("#receive_name").val($("#usr_name").val());
			$("#receive_cell").val($("#usr_cell").val());
			$("#receive_email").val($("#usr_email").val());
		}
		$("#receive_zipcode1").val($("#usr_zipcode1").val());
		$("#receive_zipcode2").val($("#usr_zipcode2").val());
		$("#receive_address1").val($("#usr_address1").val());
		$("#receive_address2").val($("#usr_address2").val());
		usr_email
		$("#receive_memo").focus();	
	});
	$("#delivery_se2").click(function (){
		$("#receive_name").val("");
		$("#receive_cell").val("");
		$("#receive_zipcode1").val("");
		$("#receive_zipcode2").val("");
		$("#receive_address1").val("");
		$("#receive_address2").val("");
		$("#receive_name").focus();
	});
	$("#delivery_se3").click(function (){
		$("#receive_name").val($("#usr_name_old").val());
		$("#receive_cell").val($("#usr_cell_old").val());
		$("#receive_zipcode1").val($("#usr_zipcode1_old").val());
		$("#receive_zipcode2").val($("#usr_zipcode2_old").val());
		$("#receive_address1").val($("#usr_address1_old").val());
		$("#receive_address2").val($("#usr_address2_old").val());
		$("#receive_memo").focus();
	});
	$("#ordEdt").click(function (e){
		e.preventDefault();
		$("#buyer_name").html("<input type='text' name='buyer_chg_name' id='buyer_chg_name' value='${memList.CSTMNM}' maxlength='15'>");
		$("#buyer_cell").html("<input type='text' name='buyer_chg_cell' id='buyer_chg_cell' value='${memList.MOBILENO1}-${memList.MOBILENO2}-${memList.MOBILENO3}' maxlength='15'>");
		$("#buyer_email").html("<input type='text' name='buyer_chg_email' id='buyer_chg_email' value='${memList.EMAIL}' maxlength='50'>");
	});
	$("#zipcodeSearch").click(function(e){
        var receiveList  = eval('(' + '[]' + ')');       
        receiveList.push({
        	receive_name: $("#receive_name").val()
        	, receive_cell: $("#receive_cell").val()
        	, receive_zipcode1: $("#receive_zipcode1").val()
        	, receive_zipcode2: $("#receive_zipcode2").val()
        	, receive_address1: $("#receive_address1").val()
        	, receive_address2: $("#receive_address2").val()
        	, receive_memo: $("#receive_memo").val()
        	, buyer_name: $("#buyer_name").val()
        	, buyer_cell: $("#buyer_cell").val()
        	, receive_memo: $("#receive_memo").val()
        }); 
         $.cookies.set('receiveList', receiveList); 
        
		location.href = "/vhmall/zipcode.vh";
	});
	var receiveList = $.cookies.get('receiveList');
	if(receiveList){
		$("#receive_name").val(receiveList[0].receive_name);
		$("#receive_cell").val(receiveList[0].receive_cell);
		$("#receive_zipcode1").val(receiveList[0].receive_zipcode1);
		$("#receive_zipcode2").val(receiveList[0].receive_zipcode2);
		$("#receive_address1").val(receiveList[0].receive_address1);
		$("#receive_address2").val(receiveList[0].receive_address2);
		$("#receive_memo").val(receiveList[0].receive_memo);
	}
	
});
</script>
<script type="text/javascript">
function pay() {
	var fm = document.payForm;
	
	
	if($("#receive_name").val() == ""){
    	alert("이름을 입력해주세요.");
    	$("#receive_name").focus();
    	return;
    }
	if($("#receive_cell").val() == ""){
    	alert("휴대폰을 입력해주세요.");
    	$("#receive_cell").focus();
    	return;
    }
	if($("#receive_zipcode1").val() == ""){
    	alert("주소를 입력해주세요.");
    	return;
    }
	if($("#receive_address2").val() == ""){
    	alert("상세주소를 입력해주세요.");
    	$("#receive_address2").focus();
    	return;
    }
	
	
	var bill_sct = $("input[name=bill_select]:checked");
    if( bill_sct.length <= 0 ){
	    alert("결제방법을 선택하세요.");
	    return;
    }
    
    var agreeChk = $('input[name="agreeMem"]').is(":checked");
    if ( agreeChk <= 0 ){
    	alert("주문동의서에 동의하셔야 주문을 하실수 있습니다.");
    	return;
    }
	
    
    $("#LGD_CUSTOM_FIRSTPAY").val( bill_sct.val() );
    
    var receiveList = $.cookies.get('receiveList');
	if(receiveList){
		if(receiveList[0].receive_name != "") $("#receive_name").val(receiveList[0].receive_name);
		if(receiveList[0].receive_cell != "") $("#receive_cell").val(receiveList[0].receive_cell);
		if(receiveList[0].receive_zipcode1 != "") $("#receive_zipcode1").val(receiveList[0].receive_zipcode1);
		if(receiveList[0].receive_zipcode2 != "") $("#receive_zipcode2").val(receiveList[0].receive_zipcode2);
		if(receiveList[0].receive_address1 != "") $("#receive_address1").val(receiveList[0].receive_address1);
		if(receiveList[0].receive_address2 != "") $("#receive_address2").val(receiveList[0].receive_address2);
		if(receiveList[0].receive_memo != "") $("#receive_memo").val(receiveList[0].receive_memo);
	}

	if($("#buyer_chg_name").val() != "" && $("#buyer_chg_name").val() != undefined)	$("#LGD_BUYER").val( $("#buyer_chg_name").val() );
	if($("#buyer_chg_email").val() != "" && $("#buyer_chg_email").val() != undefined)	$("#LGD_BUYEREMAIL").val( $("#buyer_chg_email").val() );
	
    //주문번호 생성
    var ordNo = "";
    ordNo = fnHashData();
    $("#LGD_OID").val(ordNo);
    
    //결제진행
    doPay_ActiveX();
}

function fnHashData() {
    var ordno = "000";
    $.ajax({
        type: "POST",
        url: "orderNoAjax.vh",
        async : false,
        success: function(data) {
          ordno = $.trim(data.ordno);
      }
    });
    return ordno;
}

function doPay_ActiveX() {
	$("#payForm").attr("action","startPG.vh");
	$("#payForm").submit();
}

</script>

<!-- 콘텐츠 영역 -->
	<div id="BodyWrap">
        <section>
            <h4 class="pag_title" title="주문/결제하기">주문/결제하기</h4>
            <form name="payForm" id="payForm" method="post">
            	<input type="hidden" name="LGD_OID" id="LGD_OID" value="" />			<!-- 주문번호  -->
            	<input type="hidden" name="LGD_BUYER" id="LGD_BUYER" value="${memList.CSTMNM}" />			<!-- 결제금액  -->
            	<input type="hidden" name="LGD_PRODUCTINFO" id="LGD_PRODUCTINFO" value="${pdtNm}"/>			<!-- 결제금액  -->
            	<input type="hidden" name="LGD_AMOUNT" id="LGD_AMOUNT" value="${totamt}"/>			<!-- 결제금액  -->
            	<input type="hidden" name="LGD_BUYEREMAIL" id="LGD_BUYEREMAIL" value="${memList.EMAIL}"/>			<!-- 구매자 이메일  -->
            	<input type="hidden" name="LGD_BUYERPHONE" id="LGD_BUYERPHONE" value="${memList.MOBILENO1}-${memList.MOBILENO2}-${memList.MOBILENO3}"/>			<!-- 구매자 이메일  -->            	
            	<input type="hidden" name="LGD_TIMESTAMP" id="LGD_TIMESTAMP" value="1234567890"/>			<!-- 타임스탬프  -->
            	<input type="hidden" name="LGD_CUSTOM_FIRSTPAY" id="LGD_CUSTOM_FIRSTPAY" value=""/>			<!-- 초기결제수단  -->
            
            	<input type="hidden" name="nPrdCount" id="nPrdCount" value="${nPrdCount}"/>	<!-- 총 주문갯수 -->
            
            <div id="ContentWrap4">
            	<ul class="showwindow_list4">
            		<c:forEach items="${requestScope.itemList}" var="items" varStatus="status">
	                	<li>
	                    	<a href="${contextPath}/vhmall/item_detail.vh?prdcd=${items.PRDCD}" class="thumb">
	                            <img src="http://www.vhmall.co.kr/inc/imgLoad.jsp?dirName=product/${items.CORPNO}/&fileName=${items.PRDIMG1_ENC}&thumb=Y&quality=100&size=230" />
	                        </a>
	                        <div class="windowinfo_area">
	                        	<a href="#" class="title">${items.PRDNM } </a>
	                            <p class="price">
		                            <c:choose>
		                            	<c:when test="${ items.CPNPRC > 0 }">
		                            		<span class="discount"><em>${items.SELPRC}</em>원</span> ${items.CPNPRC}원
		                            	</c:when>
		                                <c:otherwise>
		                               	 ${items.SELPRC}원
		                                </c:otherwise>
		                            </c:choose>
	                            </p>
	                            <p>
	                            	${items.BUYQTY} 개
	                            </p>
	                        </div>
	                    </li>
	               </c:forEach>
                </ul>
                <section>
                	<h5 class="hidtext" title="주문/결제관련 입력">주문/결제관련 입력</h5>
                    <div class="item_buytitarea" title="결제정보">결제정보</div>
                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="item_callist" summary="결제금액 산출내역">
                    	<colgroup>
                        <col style="width:33%">
                        <col style="width:67%">
                        </colgroup>
                        <tr>
                        	<th>주문금액</th>
                            <td><span class="dinmed">${totprc}</span>원</td>
                        </tr>
                        <tr>
                        	<th>할인금액</th>
                            <td><span class="dinmed"><c:choose><c:when test="${ totcprc > 0 }">-</c:when></c:choose>${totcprc}</span>원
                           	</td>
                        </tr>
                        <tr>
                        	<th>배송비</th>
                            <td>
                            <c:choose>
                            	<c:when test="${ dlvmspol == 1 }">배송비무료</c:when>
                            	<c:when test="${ dlvmspol == 2 }"><span class="dinmed">${dlvmsimpoprc}</span>원 (동일업체 ${dlvmsfsprc}원 이상 구입시 무료)</c:when>
                            	<c:when test="${ dlvmspol == 3 }"><span class="dinmed">${dlvmsimpoprc}</span>원</c:when>
                            </c:choose>
                            
                            </td>
                        </tr>
                        <tr>
                        	<th class="ftc_red">총 결제금액</th>
                            <td><span class="dinmed credit_price">${totamt}</span>원</td>
                        </tr>
                    </table>
                    <c:choose>
					<c:when test="${ memList.CSTMNO != null }">
                    <div class="item_buytitarea" title="구매자 정보">구매자 정보
                    	<a href="#" class="btn_blostyle1 gradation_white2" title="보내시는 분 수정" id="ordEdt">보내시는 분 수정</a>
                    </div>
                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="item_callist" summary="구매자 정보내역">
                    	<colgroup>
                        <col style="width:33%">
                        <col style="width:67%">
                        </colgroup>
                        <tr>
                        	<th>이름</th>
                            <td class="ta_l" id="buyer_name">${memList.CSTMNM}</td>
                        </tr>
                        <tr>
                        	<th>휴대폰</th>
                            <td class="ta_l" id="buyer_cell">${memList.MOBILENO1}-${memList.MOBILENO2}-${memList.MOBILENO3}</td>
                        </tr>
                        <tr>
                        	<th>이메일</th>
                            <td class="ta_l" id="buyer_email">${memList.EMAIL}</td>
                        </tr>
                        <input type="hidden" name="usr_name" id="usr_name" value="${memList.CSTMNM}">
                        <input type="hidden" name="usr_cell" id="usr_cell" value="${memList.MOBILENO1}-${memList.MOBILENO2}-${memList.MOBILENO3}">
                        <input type="hidden" name="usr_zipcode1" id="usr_zipcode1" value="${memList.HOMEZIPCODE1}">
                        <input type="hidden" name="usr_zipcode2" id="usr_zipcode2" value="${memList.HOMEZIPCODE2}">
                        <input type="hidden" name="usr_address1" id="usr_address1" value="${memList.HOMEADDR1}">
                        <input type="hidden" name="usr_address2" id="usr_address2" value="${memList.HOMEADDR2}">
                        <input type="hidden" name="usr_email" id="usr_email" value="${memList.EMAIL}">
                        
                        <input type="hidden" name="usr_name_old" id="usr_name_old" value="${pastORDList.RECVNM}">
                        <input type="hidden" name="usr_cell_old" id="usr_cell_old" value="${pastORDList.MBLNO}">
                        <input type="hidden" name="usr_zipcode1_old" id="usr_zipcode1_old" value="${pastORDList.ZIPCODE1}">
                        <input type="hidden" name="usr_zipcode2_old" id="usr_zipcode2_old" value="${pastORDList.ZIPCODE2}">
                        <input type="hidden" name="usr_address1_old" id="usr_address1_old" value="${pastORDList.ADDRESS1}">
                        <input type="hidden" name="usr_address2_old" id="usr_address2_old" value="${pastORDList.ADDRESS2}">                       
                        
                    </table>
                    </c:when>
					<c:otherwise>
					<!-- 비회원 주문 -->
                    <div class="item_buytitarea" title="구매자 정보">구매자 정보
                    	<a href="#" class="btn_blostyle1 gradation_white2" title="보내시는 분 수정">보내시는 분 수정</a>
                    </div>
                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="item_callist" summary="구매자 정보내역">
                    	<colgroup>
                        <col style="width:33%">
                        <col style="width:67%">
                        </colgroup>
                        <tr>
                        	<th>이름</th>
                            <td class="ta_l">${memList.CSTMNM}</td>
                        </tr>
                        <tr>
                        	<th>휴대폰</th>
                            <td class="ta_l">${memList.MOBILENO1}-${memList.MOBILENO2}-${memList.MOBILENO3}</td>
                        </tr>
                        <tr>
                        	<th>주소</th>
                            <td class="ta_l">
                            	<p class="zipcode"><input type=""text"" name="buyer_zipcode1" id="buyer_zipcode1" class="inpt_wauto" style="width:42px;" value="480" maxlength="3" readOnly>
                                	-
                                	<input type=""text"" name="buyer_zipcode2" id="buyer_zipcode2" class="inpt_wauto" style="width:42px;" value="252" maxlength="3" readOnly>
                                	<a href="#" class="btninli_blk" style="font-size:0.67em; letter-spacing:-0.05em;" title="우편번호찾기"><span class="btn_ins">우편번호찾기</span></a>
                                </p>
                                <div class="inpser_box bgbocol_gray mar_b5">
                                    <p>
                                        <input type="text" name="buyer_address1" id="buyer_address1" placeholder="" readOnly>
                                    </p>
                                	<!-- <a href="#" class="btn_delsi1" title="삭제">×</a>-->
                                </div>
                                <div class="inpser_box bgbocol_gray">
                                    <p>
                                        <input type="text" name="buyer_address2" id="buyer_address2" placeholder="">
                                    </p>
                                	<!-- <a href="#" class="btn_delsi1" title="삭제">×</a> -->
                                </div>
                            </td>
                        </tr>
                        <tr>
                        	<th>배송메시지</th>
                            <td class="ta_l">
                            	  <textarea name="buyer_memo" id="buyer_memo" class="txtaa_wauto1"></textarea>
                            	  <p class="page_tea">0/100</p>
                          </td>
                        </tr>
                        <tr>
                        	<th>이메일</th>
                            <td class="ta_l">
								<div class="inpser_box bgbocol_gray">
                                    <p>
                                        <input type="text" name="buyer_email" id="buyer_email" placeholder="">
                                    </p>
                                	<!-- <a href="#" class="btn_delsi1" title="삭제">×</a> -->
                                </div>
                            </td>
                        </tr>
                    </table>
                    <!--// 비회원 주문 -->
                    </c:otherwise>
                    </c:choose>
                    <div class="item_buytitarea" title="받는사람 정보">받는사람 정보</div>
                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="item_callist" summary="받는사람 정보 입력목록">
                    	<colgroup>
                        <col style="width:33%">
                        <col style="width:67%">
                        </colgroup>
                        <tr>
                        	<td colspan="2" class="bgc_gray">
                            	<div class="tac_sel">
                                    <input type="radio" name="delivery_select" id="delivery_se1" value="1" checked>
                                    <label for="delivery_se1">주문자와 동일</label>
                                    <input type="radio" name="delivery_select" id="delivery_se2" value="2">
                                    <label for="delivery_se2">신규주소</label>
                                    <input type="radio" name="delivery_select" id="delivery_se3" value="3">
                                    <label for="delivery_se3">과거배송지</label>
                                </div>
                            </td>
                        </tr>
                        <tr>
                        	<th>이름</th>
                            <td class="ta_l">
                            	<div class="inpser_box bgbocol_gray">
                                    <p>
                                        <input type="text" name="receive_name" id="receive_name" value="${memList.CSTMNM}" maxlength="15">
                                    </p>
                                	<!-- <a href="#" class="btn_delsi1" title="삭제">×</a> -->
                                </div>
                            </td>
                        </tr>
                        <tr>
                        	<th>휴대폰</th>
                            <td class="ta_l">
								<div class="inpser_box bgbocol_gray">
                                    <p>
                                        <input type="text" name="receive_cell" id="receive_cell" value="${memList.MOBILENO1}-${memList.MOBILENO2}-${memList.MOBILENO3}" maxlength="15">
                                    </p>
                                	<!-- <a href="#" class="btn_delsi1" title="삭제">×</a> -->
                                </div>
                            </td>
                        </tr>
                        <tr>
                        	<th>주소</th>
                            <td class="ta_l">
                            	<p class="zipcode"><input type="text" name="receive_zipcode1" id="receive_zipcode1" class="inpt_wauto" style="width:42px;" value="${memList.HOMEZIPCODE1}" maxlength="3" readOnly>
                                	-
                                	<input type=""text"" name="receive_zipcode2" id="receive_zipcode2" class="inpt_wauto" style="width:42px;" value="${memList.HOMEZIPCODE2}" maxlength="3" readOnly>
                                	<a href="#" class="btninli_blk" title="우편번호찾기" id="zipcodeSearch"><span class="btn_ins">우편번호찾기</span></a>
                                </p>
                                <div class="inpser_box bgbocol_gray mar_b5">
                                    <p>
                                        <input type="text" name="receive_address1" id="receive_address1" value="${memList.HOMEADDR1}" readOnly>
                                    </p>
                                	<!-- <a href="#" class="btn_delsi1" title="삭제">×</a> -->
                                </div>
                                <div class="inpser_box bgbocol_gray">
                                    <p>
                                        <input type="text" name="receive_address2" id="receive_address2" value="${memList.HOMEADDR2}">
                                    </p>
                                	<!-- <a href="#" class="btn_delsi1" title="삭제">×</a> -->
                                	<input type="hidden" name="receive_email" id="receive_email" value="${memList.EMAIL}">
                                </div>
                            </td>
                        </tr>
                        <tr>
                        	<th>배송메시지</th>
                            <td class="ta_l">
                            	  <textarea name="receive_memo" id="receive_memo" class="txtaa_wauto1" maxlength="100"></textarea>
                            	  <p class="page_tea">0/100</p>
                          </td>
                        </tr>
                    </table>
                    <div class="item_buytitarea" title="결제방법">결제방법</div>
                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="item_callist" summary="결제방법 선택 및 입력">
                    	<colgroup>
                        <col>
                        </colgroup>
                        <tr>
                        	<td class="bgc_gray">
                            	<div class="tac_sel">
                                    <input type="radio" name="bill_select" id="bill_se1" value="SC0060">
                                    <label for="bill_se1">휴대폰</label>
                                    <input type="radio" name="bill_select" id="bill_se2" value="SC0010">
                                    <label for="bill_se2">신용카드</label>
                                    <input type="radio" name="bill_select" id="bill_se3" value="SC0040">
                                    <label for="bill_se3">무통장입금</label>
                                </div>
                            </td>
                        </tr>
                        <!-- 
                        <td class="ta_l">
                        	<div class="catitle">입금은행</div>
                            <div class="mar_b12"><select name="select" id="select" class="item_option">
                                    <option>은행을 선택하세요.</option>
                                    <option>국민은행</option>
                                    <option>농협</option>
                                    <option>기업은행</option>
                                    <option>산업은행</option>
                                    <option>신한은행</option>
                                    <option>우리은행</option>
                                </select>
                            </div>
                            <div class="catitle">현금영수증</div>
                            <div class="cainve">
                            	<p>
                                	<input type="radio" name="receipt_select" id="receipt_se1" value="1">
                                    <label for="receipt_se1">개인소득공제용</label>
                                    <input type="radio" name="receipt_select" id="receipt_se2" value="2">
                                    <label for="receipt_se2">사업자증빙용</label>
                                    <input type="radio" name="receipt_select" id="receipt_se3" value="3">
                                    <label for="receipt_se3">신청안함</label>
                                </p>
                                <p>
                                	<select name="select" id="select" class="item_option">
                                        <option>발급방법을 선택하세요.</option>
                                        <option>휴대폰번호</option>
                                        <option>주민등록번호</option>
                                        <option>카드번호</option>
                                    </select>
                                </p>
                                <div class="inpser_box bgbocol_gray mar_b3">
                                    <p>
                                        <input type="text" name="textfield3" id="textfield3"  placeholder="'-'제외하고 입력해주세요.">
                                    </p>
                                	<a href="#" class="btn_delsi1" title="삭제">×</a>
                                </div>
                                <p class="smatx">무통장입금 완료 후 2일 이내 현금영수증이 발급됩니다.</p>
                            </div>
                        </td>
                         -->
                    </table>
                    <!-- 약관 동의 -->
                    <div class="item_buytitarea" title="회원가입 약관 동의">회원가입 약관 동의
                    	<div class="agr_chk">
                            <div class="inp_ckb">
                                <input type="checkbox" class="ckb" >
                                <label for="agree_check">모두동의</label>
                            </div>
                        </div>
                    </div>
                    <!-- 약관동의는 비회원일때는 비회원개인정보, 주문동의서 회원일때는 주문동의서만 노출 -->
                    <ul class="agree_cks">
                    <c:choose>
					<c:when test="${ memList.CSTMNO == null }">
                    	<li>
                        	<div class="shtit1">
                            	<div class="inp_ckb2 f_l">
                                    <input type="checkbox" class="ckb" name="agreeMem" id="agreeMem" onclick="this.checked=true">
                                    <label for="checkbox1">&nbsp;</label>
								</div>
								<p>비회원 개인정보보호 동의<span class="fts_s1 ftc_red">(필수)</span></p>
                            	<div class="btn_aghc">
                                    <a href="#" class="open">펼처보기</a>
                                </div>
                            </div>
                        </li>
                        <li class="sh_agre" style="display:block;">
                        	<div>
                          		약관동의
                            </div>
                        </li>
                        <li class="sh_agre">
                        	<div>
                          		약관동의
                            </div>
                        </li>
                    </c:when>
					<c:otherwise>
                        <li>
                        	<div class="shtit1">
                            	<div class="inp_ckb2 f_l">
                                    <input type="checkbox" class="ckb" name="agreeMem" id="agreeMem">
                                    <label for="checkbox1">&nbsp;</label>
								</div>
                            	<p>주문 동의서<span class="fts_s1 ftc_red">(필수)</span></p>
                            </div>
                        </li>
                        <li class="sh_agre2">
                        	<div>
                          		문구오류 (대체HTML로 변경해야할듯)
                            </div>
                        </li>
                    </c:otherwise>
                    </c:choose>
                    </ul>
                    <!--// 약관 동의 -->
                    <div class="btnposition_itembuy">
                    	<div class="btnwline1_red">
                        	<a href="javascript:pay();" class="gradation_red2" title="결제하기">결제하기</a>
                        </div>
                    </div>               
                </section>
            </div>
            </form>
        </section>
        <!--// 콘텐츠 영역 -->